﻿#ifndef CORDERMANAGER_H_
#define CORDERMANAGER_H_

#include <iostream>
#include <vector>

#include "CommonType.h"

namespace zl {

// order manager
class COrderManager
{
public:
	static COrderManager* Instance();
	static void Release();
	static std::string GeneratedOrderID();

    int32_t Init(CabinetInfo config);

    Order CreateOrder();
	int32_t BeginOrder(Order& order);
    int32_t FinishOrder(Order& order);
	int32_t LockOrder(Order& order);
	int32_t CancelOrder(Order& order);
    int32_t ConfirmOrder(const std::string& order_id, int32_t type);

	int32_t GetOrderInfo(const std::string& order_id, Order& order);
	int32_t GetAllOrders(
		OrderVec& vec,
        const std::string& begin_time,
		const std::string& end_time,
		const std::string& phone = "",
		const int32_t order_status = 0, 
		const int32_t order_type = -1,
		const int32_t lockerno = 0);
    int32_t GetOrderByUser(Order& order, const std::string& userid, const std::string& pwd = "");
	int32_t GetOrderByBoxno(Order& order, int32_t boxno);
	int32_t GetAllUnconfirmedOrders(OrderVec& orders);
    int32_t GetAllUsingOrders(OrderVec& orders);

protected:
	explicit COrderManager() = default;
	~COrderManager() = default;

    int32_t calculate_comfirm_flag(int32_t value, int32_t type, bool flag);

private:
	static COrderManager*			Instance_;
    static CabinetInfo		Config_;
};

}

#endif // CORDERMANAGER_H_
